/*     */ package com.zimbra.cs.account.ldap;
/*     */ 
/*     */ import com.zimbra.common.localconfig.DebugConfig;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.ILdapContext;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException;
/*     */ import com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId;
/*     */ import com.zimbra.cs.ldap.ZSearchControls;
/*     */ import com.zimbra.cs.ldap.ZSearchResultEntry;
/*     */ import com.zimbra.cs.ldap.ZSearchResultEnumeration;
/*     */ import com.zimbra.cs.ldap.ZSearchScope;
/*     */ import com.zimbra.cs.ldap.unboundid.InMemoryLdapServer;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class LdapHelper
/*     */ {
/*     */   private final LdapProv ldapProv;
/*     */   
/*     */   protected LdapHelper(LdapProv ldapProv)
/*     */   {
/*  50 */     this.ldapProv = ldapProv;
/*     */   }
/*     */   
/*     */   protected LdapProv getProv() {
/*  54 */     return this.ldapProv;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract void searchLdap(ILdapContext paramILdapContext, SearchLdapOptions paramSearchLdapOptions)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract void deleteEntry(String paramString, LdapUsage paramLdapUsage)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract void modifyAttrs(ZLdapContext paramZLdapContext, String paramString, Map<String, ? extends Object> paramMap, Entry paramEntry)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract void modifyEntry(String paramString, Map<String, ? extends Object> paramMap, Entry paramEntry, LdapUsage paramLdapUsage)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract boolean testAndModifyEntry(ZLdapContext paramZLdapContext, String paramString, ZLdapFilter paramZLdapFilter, Map<String, ? extends Object> paramMap, Entry paramEntry)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract ZSearchResultEntry searchForEntry(String paramString, ZLdapFilter paramZLdapFilter, ZLdapContext paramZLdapContext, boolean paramBoolean, String[] paramArrayOfString)
/*     */     throws LdapException.LdapMultipleEntriesMatchedException, ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ZSearchResultEntry searchForEntry(String base, ZLdapFilter filter, ZLdapContext initZlc, boolean useMaster)
/*     */     throws LdapException.LdapMultipleEntriesMatchedException, ServiceException
/*     */   {
/* 146 */     return searchForEntry(base, filter, initZlc, useMaster, null);
/*     */   }
/*     */   
/*     */   public ZSearchResultEntry searchForEntry(String base, ZLdapFilter filter, ZLdapContext initZlc, String[] returnAttrs)
/*     */     throws LdapException.LdapMultipleEntriesMatchedException, ServiceException
/*     */   {
/* 152 */     if (initZlc == null) {
/* 153 */       throw ServiceException.FAILURE("internal error", null);
/*     */     }
/* 155 */     return searchForEntry(base, filter, initZlc, false, returnAttrs);
/*     */   }
/*     */   
/*     */   public ZSearchResultEntry searchForEntry(String base, ZLdapFilterFactory.FilterId filterId, String filter, ZLdapContext initZlc, String[] returnAttrs)
/*     */     throws LdapException.LdapMultipleEntriesMatchedException, ServiceException
/*     */   {
/* 161 */     ZLdapFilter zFilter = ZLdapFilterFactory.getInstance().fromFilterString(filterId, filter);
/* 162 */     return searchForEntry(base, zFilter, initZlc, returnAttrs);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract ZAttributes getAttributes(ZLdapContext paramZLdapContext, LdapServerType paramLdapServerType, LdapUsage paramLdapUsage, String paramString, String[] paramArrayOfString)
/*     */     throws LdapException.LdapEntryNotFoundException, ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ZAttributes getAttributes(ZLdapContext initZlc, String dn, String[] returnAttrs)
/*     */     throws LdapException.LdapEntryNotFoundException, ServiceException
/*     */   {
/* 187 */     assert (initZlc != null);
/* 188 */     return getAttributes(initZlc, (LdapServerType)null, (LdapUsage)null, dn, returnAttrs);
/*     */   }
/*     */   
/*     */   public ZAttributes getAttributes(ZLdapContext initZlc, String dn) throws LdapException.LdapEntryNotFoundException, ServiceException
/*     */   {
/* 193 */     assert (initZlc != null);
/* 194 */     return getAttributes(initZlc, (LdapServerType)null, (LdapUsage)null, dn, (String[])null);
/*     */   }
/*     */   
/*     */   public ZAttributes getAttributes(LdapUsage usage, String dn) throws LdapException.LdapEntryNotFoundException, ServiceException
/*     */   {
/* 199 */     return getAttributes((ZLdapContext)null, LdapServerType.REPLICA, usage, dn, (String[])null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract ZSearchResultEnumeration searchDir(String paramString, ZLdapFilter paramZLdapFilter, ZSearchControls paramZSearchControls, ZLdapContext paramZLdapContext, LdapServerType paramLdapServerType)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ZSearchResultEnumeration searchDir(String baseDN, ZLdapFilter filter, ZSearchControls searchControls)
/*     */     throws ServiceException
/*     */   {
/* 220 */     return searchDir(baseDN, filter, searchControls, null, LdapServerType.REPLICA);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected abstract long countEntriesByNoopSearch(String paramString, ZLdapFilter paramZLdapFilter, ZSearchControls paramZSearchControls, ZLdapContext paramZLdapContext, LdapServerType paramLdapServerType)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private class CountObjectsVisitor
/*     */     extends SearchLdapOptions.SearchLdapVisitor
/*     */   {
/* 240 */     private long count = 0L;
/*     */     
/*     */     CountObjectsVisitor() {
/* 243 */       super();
/*     */     }
/*     */     
/*     */     public void visit(String dn, IAttributes ldapAttrs)
/*     */     {
/* 248 */       this.count += 1L;
/*     */     }
/*     */     
/*     */     long getCount() {
/* 252 */       return this.count;
/*     */     }
/*     */   }
/*     */   
/*     */   public long countEntries(String baseDN, ZLdapFilter filter, ZSearchControls searchControls)
/*     */     throws ServiceException
/*     */   {
/* 259 */     return countEntries(baseDN, filter, searchControls, null, LdapServerType.REPLICA);
/*     */   }
/*     */   
/*     */   public long countEntries(String baseDN, ZLdapFilter filter, ZSearchControls searchControls, ZLdapContext initZlc, LdapServerType ldapServerType)
/*     */     throws ServiceException
/*     */   {
/* 265 */     boolean noopSearchSupported = (!InMemoryLdapServer.isOn()) && (DebugConfig.ldapNoopSearchSupported);
/*     */     
/* 267 */     if (noopSearchSupported) {
/* 268 */       return countEntriesByNoopSearch(baseDN, filter, searchControls, initZlc, ldapServerType);
/*     */     }
/*     */     
/* 271 */     CountObjectsVisitor visitor = new CountObjectsVisitor();
/* 272 */     SearchLdapOptions searchOptions = new SearchLdapOptions(baseDN, filter, null, 0, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
/*     */     
/*     */ 
/*     */ 
/* 276 */     ZLdapContext zlc = initZlc;
/*     */     try {
/* 278 */       if (zlc == null) {
/* 279 */         zlc = LdapClient.getContext(ldapServerType, LdapUsage.SEARCH);
/*     */       }
/* 281 */       zlc.searchPaged(searchOptions);
/*     */     } finally {
/* 283 */       if (initZlc == null) {
/* 284 */         LdapClient.closeContext(zlc);
/*     */       }
/*     */     }
/*     */     
/* 288 */     return visitor.getCount();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public boolean compare(String dn, String attributeName, String assertionValue, ZLdapContext initZlc, boolean useMaster)
/*     */     throws ServiceException
/*     */   {
/* 296 */     throw new UnsupportedOperationException("compare operation has not been implemented");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/LdapHelper.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */